package cn.zl.ZLM.event.callback.impl;

import cn.zl.ZLM.event.callback.inter.IMKLogCallBack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * 日志输出广播
 */
@Component
public class MKLogCallBack implements IMKLogCallBack {

    private static final Logger logger = LoggerFactory.getLogger(MKLogCallBack.class);

    @Override
    public void invoke(int level, String file, int line, String function, String message) {
        // 0：TRACE 1：DEBUG 2：INFO 3：WARN 4：ERROR
        message = new String(message.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8);
        if (level == 0) {
            logger.trace("file:{} line:{} function:{} message:{}", file, line, function, message);
        } else if (level == 1) {
            logger.debug("file:{} line:{} function:{} message:{}", file, line, function, message);
        } else if (level == 2) {
            logger.info("file:{} line:{} function:{} message:{}", file, line, function, message);
        } else if (level == 3) {
            logger.warn("file:{} line:{} function:{} message:{}", file, line, function, message);
        } else if (level == 4) {
            logger.error("file:{} line:{} function:{} message:{}", file, line, function, message);
        } else {
            logger.info("level:{} file:{} line:{} function:{} message:{}", level, file, line, function, message);
        }
    }
}
